﻿@page
@model EventAckModel
@{
    Layout = "_BasicLayout";
    dynamic dict = Locale.GetDictionary("Scada.Web.Plugins.PlgMain.Areas.Main.Pages.EventAck");
    ViewBag.Title = dict.PageTitle;
    ViewBag.BodyCssClass = "modal-page";
}

@section Styles {
    <link href="~/plugins/Main/css/event-ack.min.css" rel="stylesheet" asp-append-version="true" />
}

@section Scripts {
    <script src="~/js/components/modal.js" asp-append-version="true"></script>
    <script src="~/plugins/Main/js/event-ack.js" asp-append-version="true"></script>
    <script>
        ackAllowed = @Model.AckAllowed.ToLowerString();
        closeModal = @Model.CloseModal.ToLowerString();
    </script>
}

@if (!string.IsNullOrEmpty(Model.Message))
{
    var alertClass = Model.HasError ? "alert-danger" : "alert-success";
    <div class="alert @alertClass">@Model.Message</div>
}

@if (Model.Event != null && Model.EventF != null)
{
    const string NameFormat = "[{0}] {1}";
    var obj = Model.Event.ObjNum > 0 ? string.Format(NameFormat, Model.Event.ObjNum, Model.EventF.Obj) : "";
    var dev = Model.Event.DeviceNum > 0 ? string.Format(NameFormat, Model.Event.DeviceNum, Model.EventF.Dev) : "";
    var cnl = Model.Event.CnlNum > 0 ? string.Format(NameFormat, Model.Event.CnlNum, Model.EventF.Cnl) : "";

    var sevIcon = new HtmlString(Severity.Closest(Model.Event.Severity) switch
    {
        KnownSeverity.Critical => "<i class='fa-solid fa-circle-exclamation critical'></i>",
        KnownSeverity.Major => "<i class='fa-solid fa-triangle-exclamation major'></i>",
        KnownSeverity.Minor => "<i class='fa-solid fa-triangle-exclamation minor'></i>",
        KnownSeverity.Info => "<i class='fa-solid fa-info info'></i>",
        _ => ""
    });

    var ackBadge = new HtmlString(Model.Event.Ack
        ? "<span class='badge bg-primary'>" + dict.AckYes +"</span>"
        : "<span class='badge bg-secondary'>" + dict.AckNo +"</span>");

    if (Model.AckAllowed)
    {
        <div class="alert alert-primary">@dict.AckTip</div>
        <form method="post"></form>
    }

    <table id="tblEvent" class="table-main" data-color="@Model.EventF.Color">
        <tr>
            <th>@dict.TimeRow</th>
            <td>@Model.EventF.Time</td>
        </tr>
        <tr>
            <th>@dict.ObjRow</th>
            <td>@obj</td>
        </tr>
        <tr>
            <th>@dict.DevRow</th>
            <td>@dev</td>
        </tr>
        <tr>
            <th>@dict.CnlRow</th>
            <td>@cnl</td>
        </tr>
        <tr>
            <th>@dict.DescrRow</th>
            <td>@Model.EventF.Descr</td>
        </tr>
        <tr>
            <th>@dict.SevRow</th>
            <td class="sev">@sevIcon @Model.EventF.Sev</td>
        </tr>
        <tr>
            <th>@dict.AckRow</th>
            <td>@ackBadge @Model.EventF.Ack</td>
        </tr>
    </table>
}
